package com.cicigodd.brick.plug.weixin.mini.service.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.cicigodd.brick.plug.weixin.mini.service.WeixinMiniService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;


/**
 * @author cicigodd
 * @date 2022-10-11 11:33
 */
@Slf4j
@Service
public class WeixinMiniServiceImpl implements WeixinMiniService {

    @Resource
    private WxMaService wxMaService;


    @Override
    public WxMaJscode2SessionResult getSessionInfo(String code) throws WxErrorException {
        WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
        log.info("code换取session：{}", sessionInfo);
        return sessionInfo;
    }

    @Override
    public File genQrcode(String scene, String page) throws WxErrorException {
        File file = wxMaService.getQrcodeService().createWxaCodeUnlimit(scene, page);
        return file;
    }


}
